from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-07 14:10:59.459063
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 07, Apr, 2021
Time: 14:11:03
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4189
Nobs: 254.000 HQIC: -48.1681
Log likelihood: 3027.69 FPE: 7.27868e-22
AIC: -48.6723 Det(Omega_mle): 5.14186e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.447256 0.126463 3.537 0.000
L1.Burgenland 0.070172 0.062504 1.123 0.262
L1.Kärnten -0.220942 0.054217 -4.075 0.000
L1.Niederösterreich 0.051728 0.138576 0.373 0.709
L1.Oberösterreich 0.224202 0.128191 1.749 0.080
L1.Salzburg 0.270411 0.070472 3.837 0.000
L1.Steiermark 0.146982 0.090447 1.625 0.104
L1.Tirol 0.116008 0.061667 1.881 0.060
L1.Vorarlberg -0.032314 0.057118 -0.566 0.572
L1.Wien -0.060843 0.116763 -0.521 0.602
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487901 0.149539 3.263 0.001
L1.Burgenland 0.001594 0.073910 0.022 0.983
L1.Kärnten 0.334361 0.064110 5.215 0.000
L1.Niederösterreich 0.086475 0.163862 0.528 0.598
L1.Oberösterreich -0.067876 0.151582 -0.448 0.654
L1.Salzburg 0.213547 0.083331 2.563 0.010
L1.Steiermark 0.119004 0.106952 1.113 0.266
L1.Tirol 0.138784 0.072920 1.903 0.057
L1.Vorarlberg 0.155681 0.067541 2.305 0.021
L1.Wien -0.456544 0.138070 -3.307 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295614 0.061847 4.780 0.000
L1.Burgenland 0.094774 0.030568 3.100 0.002
L1.Kärnten -0.015713 0.026515 -0.593 0.553
L1.Niederösterreich 0.035232 0.067771 0.520 0.603
L1.Oberösterreich 0.280331 0.062692 4.472 0.000
L1.Salzburg 0.019152 0.034465 0.556 0.578
L1.Steiermark 0.030043 0.044234 0.679 0.497
L1.Tirol 0.066090 0.030159 2.191 0.028
L1.Vorarlberg 0.085734 0.027934 3.069 0.002
L1.Wien 0.114224 0.057104 2.000 0.045
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214149 0.062494 3.427 0.001
L1.Burgenland 0.022002 0.030888 0.712 0.476
L1.Kärnten 0.008157 0.026792 0.304 0.761
L1.Niederösterreich 0.048205 0.068480 0.704 0.481
L1.Oberösterreich 0.400492 0.063348 6.322 0.000
L1.Salzburg 0.082925 0.034825 2.381 0.017
L1.Steiermark 0.137098 0.044696 3.067 0.002
L1.Tirol 0.048554 0.030474 1.593 0.111
L1.Vorarlberg 0.082871 0.028226 2.936 0.003
L1.Wien -0.044450 0.057701 -0.770 0.441
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.511703 0.122410 4.180 0.000
L1.Burgenland 0.084216 0.060501 1.392 0.164
L1.Kärnten 0.009273 0.052479 0.177 0.860
L1.Niederösterreich -0.017644 0.134135 -0.132 0.895
L1.Oberösterreich 0.141787 0.124082 1.143 0.253
L1.Salzburg 0.059741 0.068214 0.876 0.381
L1.Steiermark 0.068991 0.087549 0.788 0.431
L1.Tirol 0.213866 0.059691 3.583 0.000
L1.Vorarlberg 0.031734 0.055288 0.574 0.566
L1.Wien -0.095147 0.113021 -0.842 0.400
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180956 0.095373 1.897 0.058
L1.Burgenland -0.013363 0.047138 -0.283 0.777
L1.Kärnten -0.012635 0.040888 -0.309 0.757
L1.Niederösterreich -0.033478 0.104509 -0.320 0.749
L1.Oberösterreich 0.404881 0.096676 4.188 0.000
L1.Salzburg 0.020722 0.053147 0.390 0.697
L1.Steiermark -0.000698 0.068212 -0.010 0.992
L1.Tirol 0.155392 0.046507 3.341 0.001
L1.Vorarlberg 0.053523 0.043076 1.243 0.214
L1.Wien 0.249835 0.088058 2.837 0.005
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.243614 0.117827 2.068 0.039
L1.Burgenland 0.022162 0.058236 0.381 0.704
L1.Kärnten -0.065220 0.050514 -1.291 0.197
L1.Niederösterreich -0.067032 0.129113 -0.519 0.604
L1.Oberösterreich 0.018404 0.119437 0.154 0.878
L1.Salzburg 0.077436 0.065660 1.179 0.238
L1.Steiermark 0.340511 0.084271 4.041 0.000
L1.Tirol 0.459484 0.057456 7.997 0.000
L1.Vorarlberg 0.149256 0.053218 2.805 0.005
L1.Wien -0.173950 0.108790 -1.599 0.110
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153214 0.139998 1.094 0.274
L1.Burgenland 0.043000 0.069194 0.621 0.534
L1.Kärnten -0.073205 0.060019 -1.220 0.223
L1.Niederösterreich 0.164878 0.153407 1.075 0.282
L1.Oberösterreich 0.002196 0.141910 0.015 0.988
L1.Salzburg 0.206283 0.078014 2.644 0.008
L1.Steiermark 0.119524 0.100127 1.194 0.233
L1.Tirol 0.056115 0.068267 0.822 0.411
L1.Vorarlberg 0.096803 0.063231 1.531 0.126
L1.Wien 0.235825 0.129260 1.824 0.068
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.588143 0.075588 7.781 0.000
L1.Burgenland -0.039597 0.037359 -1.060 0.289
L1.Kärnten -0.025261 0.032406 -0.780 0.436
L1.Niederösterreich 0.018093 0.082828 0.218 0.827
L1.Oberösterreich 0.327943 0.076621 4.280 0.000
L1.Salzburg 0.020297 0.042122 0.482 0.630
L1.Steiermark -0.036544 0.054062 -0.676 0.499
L1.Tirol 0.087819 0.036859 2.383 0.017
L1.Vorarlberg 0.111599 0.034140 3.269 0.001
L1.Wien -0.044392 0.069791 -0.636 0.525
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.142187 0.049697 0.161787 0.218461 0.065141 0.080984 0.010164 0.153122
Kärnten 0.142187 1.000000 0.023240 0.202419 0.180147 -0.063859 0.159474 0.027171 0.307977
Niederösterreich 0.049697 0.023240 1.000000 0.239521 0.072604 0.312740 0.135980 0.035729 0.300890
Oberösterreich 0.161787 0.202419 0.239521 1.000000 0.301617 0.261601 0.089361 0.059996 0.137400
Salzburg 0.218461 0.180147 0.072604 0.301617 1.000000 0.152753 0.052977 0.090136 0.000510
Steiermark 0.065141 -0.063859 0.312740 0.261601 0.152753 1.000000 0.106206 0.096866 -0.113185
Tirol 0.080984 0.159474 0.135980 0.089361 0.052977 0.106206 1.000000 0.163587 0.146520
Vorarlberg 0.010164 0.027171 0.035729 0.059996 0.090136 0.096866 0.163587 1.000000 0.002869
Wien 0.153122 0.307977 0.300890 0.137400 0.000510 -0.113185 0.146520 0.002869 1.000000